#include "pagridplot.h"

int main(int argc, char *argv[]){ 
  logFinfo* info;  
  menu_info menu_info;

  WARNING((argc < 2,"USAGE : pagridplot file [coordinates_file]\n\nex : pagridplot grid20x20.graph.net_cost.proc_ratio [grid20x20.coords]\nthis will plot data from :\n - grid20x20.graph.net_cost.proc_ratio.log\n - grid20x20.graph.net_cost.proc_ratio.time.log\n - grid20x20.graph.net_cost.proc_ratio.bet.log\nif the coordinate file is provided you would be able to generate opendx file to visualize matchings\n"),1);

  WARNING(((info = LD_readInfo(argc,argv)) == NULL,"Error in LD_readInfo\n"),1);

  argc -= 2;
  menu_info.info1 = &argc;
  menu_info.info2 = info;

  main_menu(&(menufn_main),&menu_info);

#ifndef DEBUG
  LD_freeInfo(info);
#endif

  return 0;
}

int logfiles(logFinfo* info,int et){
  menu_labels labels;
  logFctrl    ctrl;
  menu_info   menu_info;

  labels_log(&labels);

  ctrl.info   = info;
  ctrl.labels = &labels;
  ctrl.et     = et;

  default_log(&ctrl);
  menu_info.info1 = &ctrl;

  logfirst_menu(&(menufn_logfirst),&menu_info);  

  return 1;
}

int logrun(menu_info* info){
  logFctrl* ctrl;
  logFdata* data;
  FILE* logfp;
  char buffer[PLIB_STR];
  

  WARNING((info->info1 == NULL,"logrun error 1 : info->info1 undefined\n"),0);
  ctrl = (logFctrl*)info->info1;

  /* read log file */
  if(ctrl->et == BEFORE_ET){
    sprintf(buffer,"%s.bet.log",ctrl->base);
    WARNING(((logfp = fopen(buffer,"r")) == NULL,"logrun error code 2 : cannot open %s\n",buffer),0);
    data = LD_readBetLog(logfp,ctrl);
    fclose(logfp);
  }else{
    sprintf(buffer,"%s.log",ctrl->base);
    WARNING(((logfp = fopen(buffer,"r")) == NULL,"logrun error code 3 : cannot open %s\n",buffer),0);
    data = LD_readLog(logfp,ctrl);
    fclose(logfp);
  }

  return 1;
}
